<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>数据表过滤设置</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/common-yd.js"></script>
<script type="text/javascript" src="../js/table-yd.js"></script>
<link rel="stylesheet" href="../css/common-yd.css"></link>
<link rel="stylesheet" href="../css/table-yd.css"></link>
<link rel="stylesheet" href="../css/EPRIS.css"></link>
<style type="text/css">
#filterSetTable td{
	border-bottom:1px solid #197BFF;
	border-right:1px solid #197BFF;
}
.btnCommon{
	height:30px;
	line-height:30px;
	width:80px;
	text-align:center;
	display:block;
}
</style>
</head>
<body oncontextmenu="return false">
<div id="filterSetTable" style="width:100%;"></div>
<div style="height:50px;width:100%;display:inline-flex;align-items:center;padding-left:calc(50% - 85px);border-top:1px solid #197BFF;">
	<label class="btnCommon btnSure" style="margin-right:5px;" onclick="sureTableFilterSet()">确定</label>
	<label class="btnCommon btnClose" style="margin-left:5px;" onclick="closeTableFilterSet()">取消</label>
</div>
<script type="text/javascript">
var filterTable = null;
var tableCols = null, tableFilter = null;
$(function(){
	var paramMap = getPageParameterMap();
	tableCols = paramMap.tableCols;
	tableFilter = paramMap.tableFilter;
	refreshPageElement();
	initFilterTableCol();
	if(tableFilter&&tableFilter.length>0) reshowSettedFilter();
});

function initFilterTableCol(){
	filterTable = new DataTable('filterSetTable', 
		[
			{field: 'colComment', title: '字段注释', width:120, align: 'center'}, 
		  	{field: 'multiType', title: '条件形式', width:140, align: 'center'}, 
			{field: 'filterType', title: '过滤条件', width:200, align: 'center'}, 
			{field: 'filterValue', title: '参数值', width:100, align: 'center'}, 
			{field: 'oper', title: '＋', width:140, align: 'center'}
    	]
	);
	$('#filterSetTable').find('.titleLabel[colName="oper"]').html("<span style='font-size:16px;cursor:pointer;' onclick='addNewFilterSet()'>+</span>");
	$('#filterSetTable').find('.tablePageArea').hide();
	$('#filterSetTable').find('.dataTableBodyDiv').height($('#filterSetTable').height()-38);
}

function reshowSettedFilter(){
	$('#filterSetTable').find('.dataTableBody>tbody').empty();
	if(tableFilter.length>0){
		$('#filterSetTable').find('.emptyDataTable').hide();
		$('#filterSetTable').find('.dataTableBody').show();
	}else{
		$('#filterSetTable').find('.emptyDataTable').show();
		$('#filterSetTable').find('.dataTableBody').hide();
	}
	var rowspanMap = {};
	for(var i=0;i<tableFilter.length;i++){
		var filterRow = tableFilter[i];
		var filterCol = filterRow[0];
		rowspanMap[filterCol] = rowspanMap[filterCol]?(rowspanMap[filterCol]+1):1;
	}
	for(var i=0;i<tableFilter.length;i++){
		var filterRow = tableFilter[i];
		var filterCol = filterRow[0], filterColComment = filterRow[1], filterMulti = filterRow[2], filterType = filterRow[3], filterValue = filterRow[4];
		var rowHTML = "<tr colCode='"+filterCol+"'>"
					+ "    <td class='dataCell' colCode='"+filterCol+"'>"+filterColComment+"</td>"
					+ "    <td class='dataCell' multiType='"+filterMulti+"'>"+getFilterMultiType(filterMulti)+"</td>"
					+ "    <td class='dataCell' compareType='"+filterType+"'>"+getFilterCompareType(filterType)+"</td>"
					+ "    <td class='dataCell'>"+filterValue+"</td>"
					+ "    <td class='dataCell' style='text-align:center;'>"
					+ "        <img src='../images/edit_blue.png' style='width:20px;height:20px;cursor:pointer;' onclick='editExistFilterSet(this)'>"
					+ "        <img src='../images/delete_blue.png' style='width:20px;height:20px;cursor:pointer;' onclick='deleteExistFilterSet(this)'>"
					+ "    </td>"
					+ "</tr>";
		$('#filterSetTable').find('.dataTableBody>tbody').append(rowHTML);
	}
	for(var colCode in rowspanMap){
		var spanRowEle = $('#filterSetTable').find('tr[colCode="'+colCode+'"]:first');
		spanRowEle.find('.dataCell:eq(0)').attr('rowspan', rowspanMap[colCode]);
		spanRowEle.find('.dataCell:eq(1)').attr('rowspan', rowspanMap[colCode]);
		spanRowEle.find('.dataCell:eq(4)').attr('rowspan', rowspanMap[colCode]);
		var spanHideEle = $('#filterSetTable').find('tr[colCode="'+colCode+'"]:not(:first)');
		spanHideEle.find('.dataCell:eq(0)').hide();
		spanHideEle.find('.dataCell:eq(1)').hide();
		spanHideEle.find('.dataCell:eq(4)').hide();
	}
}

function getFilterMultiType(multiType){
	if(multiType=='1'){
		return '单条件';
	}else if(multiType=='2'){
		return '或条件';
	}else if(multiType=='3'){
		return '且条件';
	}
}

function getFilterCompareType(compareType){
	if(compareType=='1'){
		return '等于';
	}else if(compareType=='2'){
		return '不等于';
	}else if(compareType=='3'){
		return '大于';
	}else if(compareType=='4'){
		return '大于等于';
	}else if(compareType=='5'){
		return '小于';
	}else if(compareType=='6'){
		return '小于等于';
	}else if(compareType=='7'){
		return '包含';
	}else if(compareType=='8'){
		return '不包含';
	}else if(compareType=='9'){
		return '开头为';
	}else if(compareType=='10'){
		return '结尾为';
	}else if(compareType=='11'){
		return '为空';
	}else if(compareType=='12'){
		return '不为空';
	}else if(compareType=='13'){
		return '空文本';
	}else if(compareType=='14'){
		return '非空文本';
	}
}

function addNewFilterSet(){
	showFrameDialog("pgColumnFilterSet.html", {title:'字段过滤设置', width:500, height:340}, {tableCols:tableCols}, function(param){
		if(param){
			var addFilterCol = param.colCode, addFilter = param.filterSet;
			for(var i=0;i<tableFilter.length;i++){
				if(tableFilter[i][0]==addFilterCol){
					showWarnDialog("该字段已设置过滤条件！");
					return;
				}
			}
			tableFilter = tableFilter.concat(addFilter);
			reshowSettedFilter();
		}
	});
}

function editExistFilterSet(editEle){
	var editCol = $(editEle).parent().parent().attr('colCode');
	var editColFilter = [];
	for(var i=0;i<tableFilter.length;i++){
		var filterRow = tableFilter[i];
		if(filterRow[0]==editCol) editColFilter.push(filterRow);
	}
	showFrameDialog("pgColumnFilterSet.html", {title:'字段过滤设置', width:500, height:340}, 
			{editCol:editCol, tableCols:tableCols, colFilter:editColFilter}, function(param){
		if(param){
			var addFilterCol = param.colCode, addFilter = param.filterSet;
			if(addFilterCol==editCol){
				var newTableFilter = [];
				var isReplaceFilter = false;
				for(var i=0;i<tableFilter.length;i++){
					if(tableFilter[i][0]!=addFilterCol){
						newTableFilter.push(tableFilter[i]);
					}else if(!isReplaceFilter){
						newTableFilter = newTableFilter.concat(addFilter);
						isReplaceFilter = true;
					}
				}
				tableFilter = newTableFilter;
			}else{
				for(var i=0;i<tableFilter.length;i++){
					if(tableFilter[i][0]==addFilterCol){
						showWarnDialog("该字段已设置过滤条件！");
						return;
					}
				}
				tableFilter = tableFilter.concat(addFilter);
			}
			reshowSettedFilter();
		}
	});
}

function deleteExistFilterSet(editEle){
	var editCol = $(editEle).parent().parent().attr('colCode');
	var leftFilterSet = [];
	for(var i=0;i<tableFilter.length;i++){
		var filterRow = tableFilter[i];
		if(filterRow[0]!=editCol) leftFilterSet.push(filterRow);
	}
	tableFilter = leftFilterSet;
	reshowSettedFilter();
}

function refreshPageElement(){
	var bodyHeight = document.body.offsetHeight;
	$('#filterSetTable').height(bodyHeight-50);
	if(filterTable!=null) filterTable.resize();
	$('#filterSetTable').find('.tablePageArea').hide();
	$('#filterSetTable').find('.dataTableBodyDiv').height($('#filterSetTable').height()-38);
}

function sureTableFilterSet(){
	closeDialog(tableFilter);
}

function closeTableFilterSet(){
	closeDialog(false);
}
</script>
</body>
</html>